package com.cn.xiongmeng.czlxz.taku;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import com.anythink.interstitial.api.ATInterstitial;
import com.anythink.splashad.api.ATSplashAd;
import com.cn.xiongmeng.czlxz.MainApplication;

public class SplashAd {
    private static final String TAG = ".taku.SplashAd";
    /* 本类，只提供展示开屏广告的代码
     * 开屏广告初始化函数定义在MainApplication中
     * 开屏广告初始化函数调用在MainActivity中*/
    public static void showSplashAd(Activity activity, FrameLayout container){
        MainApplication app = (MainApplication)(activity.getApplication());

        ATSplashAd splashAd = app.getSplashAd();

        if (splashAd == null){
            return;
        }

        if (splashAd.isAdReady()) {
            Log.d(TAG, "showSplashAd: 开屏广告is Readay");
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    container.setVisibility(View.VISIBLE);
                }
            });
            splashAd.show(activity, container);
        } else {
            Log.d(TAG, "showSplashAd: 开屏广告not Readay");
            splashAd.loadAd();; // 异步的，所以执行load后立即判断isAdReady是没有意义的
        }

    }
}
